package com.jsh.util;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginInterceptor extends HandlerInterceptorAdapter {
@Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String uri=request.getRequestURI();
    HttpSession session=request.getSession();
        if (uri.contains("/login")||session.getAttribute("key")!=null){
            return true;
        }

        if (session.getAttribute("admin")!=null){
            return true;
        }
        request.setAttribute("msg","你还未登录");
        request.getRequestDispatcher("/WEB-INF/jsp/login.jsp").forward(request,response);
        return false;
    }
}
